<template>
  <div>
    <el-form :model="queryParam" :inline=true style="display: flex">
      <el-form-item label="表名">
        <el-input v-model="queryParam.tableName" style="width:160px"/>
      </el-form-item>
      <el-form-item label="列名">
        <el-input v-model="queryParam.columnName" style="width:160px"/>
      </el-form-item>
      <el-form-item label="变量">
        <el-input v-model="queryParam.variable" style="width:160px"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="queryPage">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="id" label="序号" width="80"></el-table-column>
      <el-table-column prop="tableName" label="表名" width="120"></el-table-column>
      <el-table-column prop="columnName" label="列名" width="120"></el-table-column>
      <el-table-column prop="variable" label="变量"></el-table-column>
      <el-table-column prop="sort" label="排序"></el-table-column>
      <el-table-column prop="isValid" label="有效否">
        <template slot-scope="scope">
          <span>{{ value2Name(validEnums, scope.row.isValid) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="pageTotal>0"
      :total="pageTotal"
      :page.sync="queryParam.pageNum"
      :limit.sync="queryParam.pageSize"
      @pagination="queryPage"
    />
  </div>
</template>

<script>
import {value2Name, parseTime} from '@/utils'
import store from "../../../store";

export default {
  data() {
    return {
      // 查询参数
      pageTotal: 0,
      queryParam: {
        tableName: '',
        columnName: '',
        variable: '',
        pageNum: 1,
        pageSize: 10
      },
      validEnums: store.listDictionary('isValid'),
      tableData: []
    }
  },
  mounted() {
    this.pageList()
  },
  methods: {
    parseTime,
    value2Name,
    queryPage() {
      var _this = this
      _this.pageList()
    },
    pageList() {
      var _this = this
      this.$api.dbPageList(_this.queryParam).then(res => {
        if (res.code === '00000') {
          _this.tableData = res.data.pageList
          _this.pageTotal = res.data.pageTotal
        } else {
          _this.$message(res.msg)
        }
      }).catch(e => {
        console.log('接口访问异常!')
      })
    }
  }
}
</script>
